package com.cisdi.info.simple.service.permission.impl;

import com.cisdi.info.simple.dao.permission.RoleAndPermissionDao;
import com.cisdi.info.simple.dto.base.PageDTO;
import com.cisdi.info.simple.dto.base.PageResultDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cisdi.info.simple.entity.permission.RoleAndPermission;
import com.cisdi.info.simple.service.base.BaseService;
import com.cisdi.info.simple.service.permission.RoleAndPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class RoleAndPermissionServiceBean extends BaseService implements RoleAndPermissionService {

private static Logger logger = LogManager.getLogger();

@Autowired
private RoleAndPermissionDao roleAndPermissionDao;

public PageResultDTO findRoleAndPermissions(PageDTO pageDTO)
{
	pageDTO.setStartIndex((pageDTO.getCurrentPage()-1)*pageDTO.getPageSize());
	List<RoleAndPermission> roleAndPermissionDTOS = this.roleAndPermissionDao.findRoleAndPermissions(pageDTO);
	Long totalCount = this.roleAndPermissionDao.findRoleAndPermissionTotalCount(pageDTO);

	PageResultDTO pageResultDTO = new PageResultDTO();
	pageResultDTO.setTotalCount(totalCount);
	pageResultDTO.setDatas(roleAndPermissionDTOS);

	return pageResultDTO;
}

public List<RoleAndPermission> findAllRoleAndPermissions()
{
	return this.roleAndPermissionDao.findAllRoleAndPermissions();
}

public List<RoleAndPermission> findAllRoleAndPermissionsWithIdName()
{
	return this.roleAndPermissionDao.findAllRoleAndPermissionsWithIdName();
}

public RoleAndPermission findRoleAndPermission(Long roleAndPermissionId)
{
	return this.roleAndPermissionDao.findRoleAndPermission(roleAndPermissionId);
}

//所有外键的Name都以加载
public RoleAndPermission findRoleAndPermissionWithForeignName(Long roleAndPermissionId)
{
	return this.roleAndPermissionDao.findRoleAndPermissionWithForeignName(roleAndPermissionId);
}

public RoleAndPermission saveRoleAndPermission(RoleAndPermission roleAndPermission)
{
	this.setSavePulicColumns(roleAndPermission);
	return this.roleAndPermissionDao.saveRoleAndPermission(roleAndPermission);
}

public RoleAndPermission updateRoleAndPermission(RoleAndPermission roleAndPermission)
{
	this.setUpdatePulicColumns(roleAndPermission);
	return this.roleAndPermissionDao.updateRoleAndPermission(roleAndPermission);
}

public void deleteRoleAndPermission(Long roleAndPermissionId)
{
	this.roleAndPermissionDao.deleteRoleAndPermission(roleAndPermissionId);
}
}
